package com.youcash.ZyWallet_spring.controller;

import com.youcash.ZyWallet_spring.entity.LoansType;
import com.youcash.ZyWallet_spring.entity.NewsList;
import com.youcash.ZyWallet_spring.service.NewsListService;
import com.youcash.ZyWallet_spring.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Zhangzifeng
 */
@RestController
@RequestMapping("/news")
//类注解：可以对控制器类进行详细说明
@Api(value = "提供新闻资讯的添加、修改、删除、查询相关接口", tags = "新闻资讯管理")
@CrossOrigin
public class NewsListController {

    @Autowired
    private NewsListService newsListService;

    @GetMapping("/get")
    @ApiOperation("获取全部新闻列表的接口")
    public ResultVO listNews() {
        return newsListService.listNews();
    }

    @GetMapping("/get/{status}")
    @ApiOperation("通过状态值获取新闻列表的接口")
    @ApiImplicitParam(dataType = "Integer", name = "status", value = "新闻资讯的状态", required = true)
    public ResultVO listNewsByStatus(@PathVariable("status") Integer status) {
        return newsListService.listNewsByStatus(status);
    }

    @PutMapping("/updateStatus/{id}/{status}")
    @ApiOperation("通过id更新状态值")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "Integer", name = "id", value = "新闻列表的id", required = true),
            @ApiImplicitParam(
                    dataType = "Integer", name = "status", value = "状态", required = true)
    })
    public ResultVO updateStatusById(@PathVariable("id") Integer id,
                                     @PathVariable("status") Integer status) {
        return newsListService.updateStatus(id, status);
    }

    @PostMapping("/add")
    @ApiOperation("增加新闻列表的接口")
    public ResultVO addLoans(@RequestBody NewsList newsList) {
        return newsListService.addNews(newsList);
    }

    @ApiOperation("用于修改新闻的接口")
    @PutMapping("/updateInfo/{id}")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "string", name = "title", value = "新闻标题", required = false),
            @ApiImplicitParam(
                    dataType = "string", name = "article", value = "新闻网址", required = false)
    })
    public ResultVO updateInfo(@PathVariable("id") Integer id,
                               String title,
                               String article,
                               String updatetime) {
        return newsListService.updateInfo(id, title, article, updatetime);
    }
}
